﻿using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
//using Google.API.Search;
using Samurai.DAL;
using Samurai.Infrastructure;
using Samurai.MovieIndustry;
using System.Collections.Generic;

namespace Samurai.Client.Commands
{
    public class SearchCommand : ICommand
    {
        private readonly ObservableCollection<Movie> _movies;

        public SearchCommand(ObservableCollection<Movie> movies)
        {
            _movies = movies;
        }

        public void Execute(object parameter)
        {
            if(parameter != null && !string.IsNullOrEmpty(parameter.ToString()))
            {
                var movies = Manager.Instance.FindMovieByTitle(parameter.ToString());

                _movies.Clear();

                foreach (var movieData in movies)
                {
                    _movies.Add(movieData);
                }
            }
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;
    }    
}